package java6699.lesson13;

/**
 * @program: java_zzx
 * @description:
 * @author: zzx
 * @create: 2022-11-28 10:12
 **/
public class ThreadAndRunnable6699 {
    public static void main(String[] args) {
        // TicketThread6699.saleByThread6699();
        TicketRunnable6699.saleByThread6699();
    }
}

class TicketThread6699 extends Thread {
    private int tickets = 1;

    public TicketThread6699(String name) {
        super(name);
    }

    public static void saleByThread6699() {
        TicketThread6699 t1 = new TicketThread6699("周梓希1");
        TicketThread6699 t2 = new TicketThread6699("周梓希2");
        TicketThread6699 t3 = new TicketThread6699("周梓希3");
        t1.start();
        t2.start();
        t3.start();
    }

    @Override
    public void run() {
        while (tickets <= 8) {
            String name = Thread.currentThread().getName();
            System.out.println(name + "第" + tickets++ + "张票");
        }
    }
}

class TicketRunnable6699 implements Runnable {
    private int tickets = 1;

    public static void saleByThread6699() {
        TicketRunnable6699 ticket = new TicketRunnable6699();
        new Thread(ticket, "周梓希1").start();
        new Thread(ticket, "周梓希2").start();
        new Thread(ticket, "周梓希3").start();
    }

    @Override
    public void run() {
        while (tickets <= 8) {
            String name = Thread.currentThread().getName();
            System.out.println(name + "第" + tickets++ + "张票");
        }
    }
}
